package cn.sunshine.ymcc.mq.producer;

import cn.sunshine.ymcc.domain.MediaFile;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class MediaProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public Boolean sendMediaPush(MediaFile mediaFile){
        // 这里传message比较安全，免得后面一大堆序列化
        Message<?> message = MessageBuilder.withPayload(mediaFile).build();
        SendResult syncSend = rocketMQTemplate.syncSend("topic-media:tags-media", "message");
        // 这里要接收参数，OK才是真的OK
        SendStatus sendStatus = syncSend.getSendStatus();
        if (sendStatus == SendStatus.SEND_OK){
            return true;
        }

        return false;
    }


}
